package com.anycl.design.structural.flyweight.demo;

import java.util.HashMap;

public class ExamInfoFactory {

    public static HashMap<String, ExamInfo> pool = new HashMap<>();

    public static ExamInfo getExamInfo(String subject) {
        ExamInfo examInfo = null;
        if (!pool.containsKey(subject)) {
            System.out.println("建立对象，并放到池中..." + subject);
            examInfo = new ExamInfo(subject);
            pool.put(subject, examInfo);
        } else {
            examInfo = pool.get(subject);
            System.out.println("直接从池中获取..." + subject);
        }
        return examInfo;
    }
}
